import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);

import Home from "../views/Home/Home";
import My from "../views/My/My";
const Login = {
  render: (h) => {
    return <div>登录</div>;
  },
};
const UserInfo = {
  render: (h) => {
    return <div>用户信息</div>;
  },
};
const NotFound = {
  render: (h) => {
    return <div>你的页面打了烊</div>;
  },
};

const ShopCar = {
  render: (h) => {
    return <div>购物车</div>;
  },
};
const router = new VueRouter({
  // mode: "history",
  mode: "hash",
  routes: [
    {
      path: "/home",
      component: Home,
    },
    {
      path: "/shopcar",
      component: ShopCar,
    },
    {
      name: "my",
      props: true, // 开启组件传参
      path: "/my",
      component: My,
      children: [
        // 错误案例千万不能加/ 表示跟路径
        // {
        //   path: "/userinfo",
        //   component: UserInfo,
        // },
        {
          path: "/my/userinfo",
          component: UserInfo,
        },
        {
          path: "login",
          component: Login,
        },
        {
          path: "/my",
          redirect: "/my/userinfo",
        },
      ],
    },
    {
      path: "/",
      redirect: "/home",
    },
    {
      path: "*",
      component: NotFound,
    },
  ],
});
export default router;
